
** Loading data - generated in dofile: data05
use "$data\minwage_data5_estimation_2012_2015.dta", clear
keep if inrange(tline,-24,24)  // 49 event-month oberservation window & INCLUDING apprentices

replace emplyd = emplyd * 100
replace felt_200_trim = 0 if felt_200_trim == . // if no reported earnings, earnings set to zero
replace timeantF12_trim = 0 if timeantF12_trim ==. // if no reported hours, hours set to zero
gen emonth = ym(cohort, brthmnth) 

 qui: tab tline, gen(Dtime) // 49 event months
 qui: tab month, gen(Dmnth) // 48 Calendar months
 qui: tab cohort, gen(Dcoh) // 8 birth cohorts
 qui: tab emonth, gen(Dbmonth) // 96 birth months
 ge tline_pos = tline+ 25

 egen cohmxmonth = group(tline month) // month cohorts 2352 
 
** Time dummies 
ge Dtime0 = tline>=0
ge DtimeZ = tline == 0
ge Dtimem2 = tline == -2
ge Dtimem1 = tline == -1
ge Dtimep1 = tline == 1
ge Dtimep2 = tline == 2

** Age polynomial
 ge tline_pos_sq=tline_pos*tline_pos
 ge tline_pos_cu=tline_pos*tline_pos*tline_pos
 ge tline_pos_4th=tline_pos*tline_pos*tline_pos*tline_pos
 ge tline_pos_5th=tline_pos*tline_pos*tline_pos*tline_pos*tline_pos

** Table 2: Estimates of the Effect of the Minimum Wage Hike at age 18
local x = 1 // starting value used for excel document w resultss
foreach var in emplyd calc_hrly_wage{
	
	** Coln. 1. Baseline regression 5 degree age polynomial including dummy at event time 0
	local x = `x' + 2
	reg `var' tline_pos tline_pos_sq tline_pos_cu tline_pos_4th tline_pos_5th Dtime0 DtimeZ, vce(cl cohmxmonth)
	putexcel set "$out\Apndx_Table3_incl_apprentices_reg_estimats_dmethd_dofile_reg06.xls", sheet(Estimates) modify
		#d; 
		putexcel A`x'=("`var'");  putexcel E`x'=("Obs.");  
		putexcel B`x'=("Beta"); putexcel C`x'=("[95% Conf. Interval]");
		putexcel G`x'=("Delta"); putexcel H`x'=("[95% Conf. Interval]"); 
		
		local x = `x' + 1; putexcel E`x' =(e(N));
		matrix b=[_b[Dtime0], _b[Dtime0] - 1.96*_se[Dtime0], _b[Dtime0] + 1.96*_se[Dtime0]];
		putexcel B`x'=matrix(b);
		putexcel A`x' =("Baseline (dummy e-time[0;0])"); 
		#d cr

	nlcom delta: _b[Dtime0] / (_b[_cons]+_b[tline_pos]*25+_b[tline_pos_sq]*25^2+_b[tline_pos_cu]*25^3+_b[tline_pos_4th]*25^4+_b[tline_pos_5th]*25^5+_b[Dtime0]*0.5), post
	putexcel set "$out\Apndx_Table3_incl_apprentices_reg_estimats_dmethd_dofile_reg06.xls", sheet(Estimates) modify
		#d; 
		matrix b=[_b[delta], _b[delta] - 1.96*_se[delta], _b[delta] + 1.96*_se[delta]];
		putexcel G`x'=matrix(b);
		#d cr
	
	** Coln. 2. Month Fixed Effects
	local x = `x' + 1
	reg `var' tline_pos tline_pos_sq tline_pos_cu tline_pos_4th tline_pos_5th Dtime0 DtimeZ Dmnth1-Dmnth23 Dmnth25-Dmnth48, vce(cl cohmxmonth)
		putexcel set "$out\Apndx_Table3_incl_apprentices_reg_estimats_dmethd_dofile_reg06.xls", sheet(Estimates) modify
		#d; 
		putexcel E`x' =(e(N));
		matrix b=[_b[Dtime0], _b[Dtime0] - 1.96*_se[Dtime0], _b[Dtime0] + 1.96*_se[Dtime0]];
		putexcel B`x'=matrix(b);
		putexcel A`x' =("Month FE: baseline month24");
		#d cr
		
	nlcom delta: _b[Dtime0] / (_b[_cons]+_b[tline_pos]*25+_b[tline_pos_sq]*25^2+_b[tline_pos_cu]*25^3+_b[tline_pos_4th]*25^4+_b[tline_pos_5th]*25^5+_b[Dtime0]*0.5), post
		putexcel set "$out\Apndx_Table3_incl_apprentices_reg_estimats_dmethd_dofile_reg06.xls", sheet(Estimates) modify
		#d; 
		matrix b=[_b[delta], _b[delta] - 1.96*_se[delta], _b[delta] + 1.96*_se[delta]];
		putexcel G`x'=matrix(b);
		#d cr

	** Coln. 3. Month & Birth cohort (month) Fixed Effects
	local x = `x' + 1
	reg `var' tline_pos tline_pos_sq tline_pos_cu tline_pos_4th tline_pos_5th Dtime0 DtimeZ Dmnth1-Dmnth23 Dmnth25-Dmnth48 ///
			  Dbmonth1-Dbmonth47 Dbmonth49-Dbmonth94, vce(cl cohmxmonth)
		putexcel set "$out\Apndx_Table3_incl_apprentices_reg_estimats_dmethd_dofile_reg06.xls", sheet(Estimates) modify
		#d; 
		putexcel E`x' =(e(N));
		matrix b=[_b[Dtime0], _b[Dtime0] - 1.96*_se[Dtime0], _b[Dtime0] + 1.96*_se[Dtime0]];
		putexcel B`x'=matrix(b);
		putexcel A`x' =("Month&Cohort FE: baseline month24&cohort48");
		#d cr

	nlcom delta: _b[Dtime0] / (_b[_cons]+ _b[tline_pos]*25+_b[tline_pos_sq]*25^2+_b[tline_pos_cu]*25^3+_b[tline_pos_4th]*25^4+_b[tline_pos_5th]*25^5+_b[Dtime0]*0.5), post
		putexcel set "$out\Apndx_Table3_incl_apprentices_reg_estimats_dmethd_dofile_reg06.xls", modify sheet(Estimates)
		#d; 
		matrix b=[_b[delta], _b[delta] - 1.96*_se[delta], _b[delta] + 1.96*_se[delta]];
		putexcel G`x'=matrix(b);
		#d cr
	
	** Coln. 4. Month & Birth cohort (month) Fixed Effects + 5 time dummies around event time 0.
	local x = `x' + 1
	reg `var' tline_pos tline_pos_sq tline_pos_cu tline_pos_4th tline_pos_5th Dtime0 DtimeZ Dmnth1-Dmnth23 Dmnth25-Dmnth48 ///
			  Dbmonth1-Dbmonth47 Dbmonth49-Dbmonth94 Dtimem2 Dtimem1 Dtimep1 Dtimep2, vce(cl cohmxmonth)
		putexcel set "$out\Apndx_Table3_incl_apprentices_reg_estimats_dmethd_dofile_reg06.xls", sheet(Estimates) modify
		#d; 
		putexcel E`x' =(e(N));
		matrix b=[_b[Dtime0], _b[Dtime0] - 1.96*_se[Dtime0], _b[Dtime0] + 1.96*_se[Dtime0]];
		putexcel B`x'=matrix(b);
		putexcel A`x' =("Month&Cohort FE & 5 event time dummies: baseline month24&cohort48");
		#d cr

	nlcom delta: _b[Dtime0] / (_b[_cons]+ _b[tline_pos]*25+_b[tline_pos_sq]*25^2+_b[tline_pos_cu]*25^3+_b[tline_pos_4th]*25^4+_b[tline_pos_5th]*25^5+_b[Dtime0]*0.5), post
		putexcel set "$out\Apndx_Table3_incl_apprentices_reg_estimats_dmethd_dofile_reg06.xls", modify sheet(Estimates)
		#d; 
		matrix b=[_b[delta], _b[delta] - 1.96*_se[delta], _b[delta] + 1.96*_se[delta]];
		putexcel G`x'=matrix(b);
		#d cr
	
	** Coln. 5. Non parametric estimate
	local x = `x' + 1
	reg `var' Dtime0 if tline_pos ==24 | tline_pos ==26, vce(cl cohmxmonth)
		putexcel set "$out\Apndx_Table3_incl_apprentices_reg_estimats_dmethd_dofile_reg06.xls", sheet(Estimates) modify
		#d; 
		putexcel E`x' =(e(N));
		matrix b=[_b[Dtime0], _b[Dtime0] - 1.96*_se[Dtime0], _b[Dtime0] + 1.96*_se[Dtime0]];
		putexcel B`x'=matrix(b);
		putexcel A`x' =("Non-parametric");
		#d cr

	nlcom delta: _b[Dtime0] / ((_b[_cons]+(_b[_cons]+_b[Dtime0]))*0.5), post
		putexcel set "$out\Apndx_Table3_incl_apprentices_reg_estimats_dmethd_dofile_reg06.xls", modify sheet(Estimates)
		#d; 
		matrix b=[_b[delta], _b[delta] - 1.96*_se[delta], _b[delta] + 1.96*_se[delta]];
		putexcel G`x'=matrix(b);
		#d cr
}

